package com.qys.livesMall.anchor.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.qys.livesMall.anchor.mapper.AnchorRewardConfigMapper;
import com.qys.livesMall.anchor.model.entity.AnchorRewardConfig;
import com.qys.livesMall.anchor.model.vo.lives.sys.AnchorRewardConfigVO;
import com.qys.livesMall.anchor.service.AnchorRewardConfigService;
import com.qys.livesMall.common.utils.ParamCheckUtil;
import com.qys.livesMall.common.utils.file.FileUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 主播奖励配置(AnchorRewardConfig)表服务实现类
 *
 * @author makejava
 * @since 2023-10-24 15:13:59
 */
@Service("anchorRewardConfigService")
public class AnchorRewardConfigServiceImpl extends ServiceImpl<AnchorRewardConfigMapper, AnchorRewardConfig> implements AnchorRewardConfigService {

    @Override
    public List<AnchorRewardConfigVO> getPage(Integer type) {
        List<AnchorRewardConfig> list = baseMapper.selectList(Wrappers.<AnchorRewardConfig>lambdaQuery().eq(AnchorRewardConfig::getAwardType, type));
        List<AnchorRewardConfigVO> voList = Lists.newArrayList();
        for (AnchorRewardConfig config : list) {
            AnchorRewardConfigVO configVO = new AnchorRewardConfigVO();
            BeanUtils.copyProperties(config, configVO);
            voList.add(configVO);
        }
        return voList;
    }

    @Override
    @Transactional
    public void add(AnchorRewardConfigVO dto) {
        ParamCheckUtil.checkField(dto, false, "awardType", "awardCondition", "awardAmount");
        AnchorRewardConfig anchorRewardConfig = new AnchorRewardConfig();
        BeanUtils.copyProperties(dto,anchorRewardConfig);
        saveOrUpdate(anchorRewardConfig);
    }

    @Override
    public void del(Long id) {
        removeById(id);
    }
}

